<template>
	<view>
	</view>
</template>
<script>'os'
	import {mapMutations} from 'vuex'
	export default {
		data() {
			return {
				comm_img_url: '',
				backUrl:'',
				refer_code:'',
			}
		},
		onLoad(option) {
			this.comm_img_url = this.$c.appImg
			this.getTokenMsg()
			let pages=getCurrentPages()
			if(pages.length>1){
				this.backUrl = pages[pages.length-2].__page__.fullPath
				uni.setStorageSync("backUrl",this.backUrl)
			}
			else{
				this.backUrl =uni.getStorageSync("backUrl")
			}
			if(option.scene){
				this.refer_code = option.scene
			}
		},
		methods: {
			...mapMutations(['login']),
			getTokenMsg() {
				let code = uni.getStorageSync("code") ?? this.refer_code
				this.$u.api.new_login_reg({
						refer_code: code //'Blx3Cp'
					})
					.then(res => {
						
						if (res.status) {
							// uni.setStorageSync('token', res.msg.token); 现在没token 走cookie 
							uni.setStorageSync('userInfo', res.msg.userinfo);
							this.login(res.msg.userinfo)
							console.log('backUrl---',this.backUrl);
							let route = this.backUrl.split('?')[0]
							if(route == '/pages/my/my' || route == '/pages/converge/converge' || route =='/pages/Station/Station'){
								uni.switchTab({
									url:this.backUrl
								})
							}else{
								if(!this.backUrl){
									uni.switchTab({
										url:'/pages/converge/converge'
									})
								}
								uni.redirectTo({
									url:this.backUrl
								})
							}
							return
						}
						if (res.code == 505) {
							let url = `${window.location.protocol}//${window.location.host}`
							let returnUrl= encodeURIComponent(`${url}/#/pages/login/login`)
							window.location.replace(`${this.$c.domain}/account/oauth2_wechat?redirect_url=${returnUrl}`)
							return
						}
						this.$u.toast(res.msg)
						setTimeout(()=>{
							uni.switchTab({
								url:'/pages/converge/converge'
							})
						},2000)
						
					})
					.catch(err => {
						this.$u.toast(err.msg)
					})
			}
		}
	}
</script>

<style lang="scss">
</style>